<template>
  <div v-loading="loading" class="account-box">
    <el-form ref="form" :model="form" label-width="180px">
      <el-form-item label="支付超时时间（分钟）" maxlength="20">
        <el-input-number v-model="form['cancelTime']" :min="2" label="超时时间"/>
        <el-alert
          :closable="false"
          title="注：订单在设定的时间内未完成支付操作，系统会自动取消。"
          type="info"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button @click="$router.back()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: {},
    data() {
      return {
        loading: false,
        // 订单设置
        form: {
          // 超时时间
          cancelTime: 1
        }
      }
    },
    mounted() {
      this.loadData();
    },
    methods: {
      // 加载数据
      loadData(){
        (async () => {
          this.loading = true;
          const result = await this.$service.applicationGetOrderSetting();
          this.loading = false;
          if (result.code === 0) {
            this.form = Object.assign(this.form, result.data || {});
          }
        })();
      },

      // 提交
      onSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            (async () => {
              const params = Object.assign({}, this.form);
              const result = await this.$service.applicationUpdateOrderSetting(params);
              if (result.code === 0) {
                this.$message.success('操作成功~');
              } else {
                this.$message.error(result.msg);
              }
            })();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>
